package com.pucong.gitee.database.backup.database.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pucong.gitee.database.backup.common.entity.BackupDatabase;
import com.pucong.gitee.database.backup.common.entity.BackupExeSqlLog;
import com.pucong.gitee.database.backup.database.mapper.BackupExeSqlLogMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BackupExeSqlLogServiceImpl implements BackupExeSqlLogService{

    @Autowired
    private BackupExeSqlLogMapper backupExeSqlLogMapper;

    @Override
    public IPage<BackupExeSqlLog> getExeSqlLogListByPage(int pageNum, int pageSize, BackupExeSqlLog backupExeSqlLog) {
        Page<BackupExeSqlLog> page = new Page<>(pageNum, pageSize);
        //构造分页查询
        LambdaQueryWrapper<BackupExeSqlLog> params = new LambdaQueryWrapper<>();
        params.eq(StringUtils.isNotBlank(backupExeSqlLog.getId()),BackupExeSqlLog::getId,backupExeSqlLog.getId())
                .eq(StringUtils.isNotBlank(backupExeSqlLog.getDatabaseName()),BackupExeSqlLog::getDatabaseName,backupExeSqlLog.getDatabaseName());

        params.orderByDesc(BackupExeSqlLog::getExeTime);
        IPage<BackupExeSqlLog> backupDatabaseIPage = backupExeSqlLogMapper.selectPage(page, params);
        return backupDatabaseIPage;
    }

    @Override
    public BackupExeSqlLog getExeSqlLogById(String id) {
        return backupExeSqlLogMapper.selectById(id);
    }
}
